#include "TaobaoCrawler.h"
#include <iostream>

TaobaoCrawler::TaobaoCrawler(void)
{
}

TaobaoCrawler::~TaobaoCrawler(void)
{
}

bool TaobaoCrawler::initUrl(City from, City to , string date)
{

	string url = "http://jipiao.taobao.com/flight_search_result.htm?";

	string head = "_fmh.fl._0.t=0&";
	string tail = "&_fmh.fl._0.r=&_fmh.fl._0.so=2&_fmh.fl._0.tr=1&_fmh.fl._0.c=&_fmh.fl._0.fl=&_fmh.fl._0.ca=&_fmh.fl._0.cab=&_fmh.fl._0.sp=&_fmh.fl._0.supp=&_fmh.fl._0.ci=&_fmh.fl._0.spt=&_fmh.fl._0.sup=&_fmh.fl._0.suppl=&_fmh.fl._0.resup=&_fmh.fl._0.resu=&_fmh.fl._0.se=&_fmh.fl._0.sel=&_fmh.fl._0.a=&shopId=";

	/*
	* _fmh.fl._0.st=ZUH
	* &_fmh.fl._0.s=%D6%E9%BA%A3
	* &_fmh.fl._0.e=%C9%CF%BA%A3
	* &_fmh.fl._0.en=SH
	* &_fmh.fl._0.sta=2008-12-18
	* &_fmh.fl._0.su=ZUH
	* &_fmh.fl._0.res=SH
	*/
	string re = url + head;
	string tmp = "";
//	string s1 = "%B9%E3%D6%DD";
//	string s2 = "%D6%A3%D6%DD";
	tmp+=("_fmh.fl._0.st=" + from.cityCode);
	tmp+=("&_fmh.fl._0.s=" + from.urlencode());
	tmp+=("&_fmh.fl._0.en=" + to.cityCode );
	tmp+=("&_fmh.fl._0.e=" + to.urlencode());
	tmp+=("&_fmh.fl._0.sta=" + date);
	tmp+=("&_fmh.fl._0.su=" + from.cityCode);
	tmp+=("&_fmh.fl._0.res=" + to.cityCode);
	re += tmp;
	re += tail;
	this->m_url = re;
#ifdef _DEBUG
	cout<<m_url<<endl;
#endif
	return true;
}

void TaobaoCrawler::craw()
{
	HttpProcess    http(15000);   
	;
	http.isVerbose ==false;
	if (http.getResponse(m_url))
	{
		this->m_content = http.content;

#ifdef _DEBUG
		ofstream ofs("taobao2.html");
		ofs<<m_content;
		ofs.close();
		//cout<<m_content<<endl;
#endif
	}
}
